#include <stdio.h>
#include <gmp.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

int main(int argc, char **argv) {
  int count = 0;

  mpz_t t;
  mpz_init(t);
  mpz_set_ui(t, 1UL);

  unsigned long n = 1UL;

  do {
    mpz_t step;
    mpz_init(step);
    mpz_set_ui(step, n);
    mpz_mul_ui(step, step, 4UL);
    mpz_add_ui(step, step, 2UL);

    mpz_add(t, t, step);
    n++;

    if (mpz_probab_prime_p(t, 10) != 0) {
      count++;

      if (count % 1000 == 0) {
        fprintf(stderr, "+ %lu\n", n);
      }
    }

    mpz_clear(step);
  } while (n <= 50000000UL);

  printf("%d prime integers\n", count);

  return 0;
}
